﻿using IDAL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class CardDAL<T> :ICardDAL<T> where T : class
    {
        public CardDAL(MyDbContext myDb)
        {
            MyDb = myDb;
        }

        public MyDbContext MyDb { get; }

        public async Task<int> AddAsync(T t)
        {
            await MyDb.Set<T>().AddAsync(t);
            return await MyDb.SaveChangesAsync();
        }

        public async Task<int> DelAsync(T t)
        {
            MyDb.Set<T>().Remove(t);
            return await MyDb.SaveChangesAsync();
        }

        public IQueryable<T> GetAll()
        {
            return MyDb.Set<T>();
        }

        public async Task<int> UpdAsync(T t)
        {
            MyDb.Set<T>().Update(t);
            return await MyDb.SaveChangesAsync();
        }
    }
}
